* This file codes Study 2 data for Timothy J. Ryan, 
* "Actions Versus Consequences in Political Arguments: Insights 
* from Moral Psychology" (JOP). Analysis was conducted on 
* Stata/SE 14.2 for Mac (64-bit Intel).

insheet using "Study2_raw.csv", clear

* Gender
recode gender (6=.)

* Partisanship
recode pidr (8=.)

* Experiment condition
gen effective = 0
replace effective = 1 if cond=="e"

* Issue attitudes
foreach iss in sy ss gc cb nu {
	replace `iss'1 = `iss'1-1
	*gen `iss'ext = `iss'1 / 6
	gen `iss'extfold = sqrt((`iss'1 - 3)^2) / 3
	gen `iss'imp = (`iss'2 - 1) / 4
	gen `iss'relev = (`iss'3 - 1) / 4
	gen `iss'mor1 = (`iss'4 - 1) / 4
	gen `iss'mor2 = (`iss'5 - 1) / 4
	}
	
foreach iss in sy ss gc cb nu {
	alpha `iss'mor1 `iss'mor2, gen(`iss'mor)
	}

/* Delete this later
sort sy1
br sy8-sy15 sy1
sort ss1
br ss8-ss16 ss1
sort gc1
br gc8-gc15 gc1
sort cb1 
br cb8-cb15 cb1
sort nu1
br nu8-nu15 nu1
*/

* Deont vs. Conseq arguments
gen syd = ((sy8 + sy9) - 2) / 8 if sy1<4
replace syd = ((sy12 + sy13) - 2) / 8 if sy1>=4
gen syc = ((sy10 + sy11) - 2) / 8 if sy1<4
replace syc = ((sy14 + sy15) - 2) / 8 if sy1>=4
gen sydpref = syd - syc

gen ssd = ((ss9 + ss10) - 2) / 8 if ss1<4
replace ssd = ((ss14 + ss15) - 2) / 8 if ss1>=4
gen ssc = ((ss8 + ss11) - 2) / 8 if ss1<4
replace ssc = ((ss13 + ss16) - 2) / 8 if ss1>=4
gen ssdpref = ssd - ssc

gen gcd = ((gc9 + gc11) - 2) / 8 if gc1<4
replace gcd = ((gc13 + gc15) - 2) / 8 if gc1>=4
gen gcc = ((gc8 + gc10) - 2) / 8 if gc1<4
replace gcc = ((gc12 + gc14) - 2) / 8 if gc1>=4
gen gcdpref = gcd - gcc

gen cbd = ((cb8 + cb9) - 2) / 8 if cb1<4
replace cbd = ((cb12 + cb13) - 2) / 8 if cb1>=4
gen cbc = ((cb10 + cb11) - 2) / 8 if cb1<4
replace cbc = ((cb14 + cb15) - 2) / 8 if cb1>=4
gen cbdpref = cbd - cbc

gen nud = ((nu9 + nu11) - 2) / 8 if nu1<4
replace nud = ((nu13 + nu15) - 2) / 8 if nu1>=4
gen nuc = ((nu8 + nu10) - 2) / 8 if nu1<4
replace nuc = ((nu12 + nu14) - 2) / 8 if nu1>=4
gen nudpref = nud - nuc

save "Study2_working_wide.dta", replace
keep caseid symor ssmor gcmor cbmor numor *extfold *imp *relev *dpref effective

foreach iss in sy ss gc cb nu {
	foreach var in mor extfold imp relev dpref {
		rename `iss'`var' `var'`iss'
		}
	}
	
reshape long mor extfold imp relev dpref, i(caseid effective) j(sy) string
encode sy, gen(issue)
drop sy

save "Study2_working_long.dta", replace
